package team.archai.nexus.boot.config;

import io.undertow.Undertow;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
 * @description: https配置
 * @author: lishibin
 * @create: 2020-06-26 13:21
 **/
@Configuration
@ConditionalOnProperty(name = "server.ssl.enabled", havingValue = "true")
@ComponentScan("team.archai.nexus")
public class WebServerFactoryCustomizerConfig implements WebServerFactoryCustomizer<UndertowServletWebServerFactory> {

    @Value("${server.http1.1.port}")
    private int httpPort;


    @Override
    public void customize(UndertowServletWebServerFactory factory) {
        factory.addBuilderCustomizers((Undertow.Builder builder) -> {
            builder.addHttpListener(httpPort, "0.0.0.0");
        });
    }
}
